package com.youpai.platform.order.web.api;

import com.youpai.platform.common.entity.resp.BaseResponse;
import com.youpai.platform.order.service.service.OrderService;
import com.youpai.platform.order.web.entity.dto.OrderDto;
import com.youpai.platform.order.web.entity.dto.OrderListDto;
import com.youpai.platform.order.web.entity.req.*;
import com.youpai.platform.order.web.entity.resp.OrderResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @time: 2022/8/4 1:31 下午
 * @author: welles
 * @description: 订单controller
 */
@Slf4j
@RestController
@RequestMapping(value = "/order")
@Api(value = "OrderController", tags = "订单相关")
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiOperation(value = "创建订单")
    @PostMapping(value = "/create")
    public BaseResponse<OrderResp> createOrder(@RequestBody CreateOrderReq req) {
        return BaseResponse.success(orderService.createOrder(req));
    }

    @ApiOperation(value = "获取订单详情")
    @PostMapping(value = "/get")
    public BaseResponse<OrderDto> getOrder(@RequestBody GetOrderReq req) {
        return BaseResponse.success(orderService.getOrder(req));
    }

    @ApiOperation(value = "虚拟支付接口")
    @PostMapping(value = "/pay")
    public BaseResponse<OrderResp> payOrder(@RequestBody PayOrderReq req) {
        return BaseResponse.success(orderService.payOrder(req));
    }

    @ApiOperation(value = "获取订单列表")
    @PostMapping(value = "/list")
    public BaseResponse<List<OrderListDto>> listOrder(@RequestBody ListOrderReq req) {
        return BaseResponse.success(orderService.listOrder(req));
    }

    @ApiOperation(value = "修改订单状态")
    @PostMapping(value = "/updateStatus")
    public BaseResponse<OrderResp> updateOrderStatus(@RequestBody UpdateOrderReq req) {
        return BaseResponse.success(orderService.updateOrderStatus(req));
    }
}
